import java.util.ArrayList;
import java.util.List;

public class Solution228 {
    public List<String> summaryRanges(int[] nums) {
        if (nums.length==0){
            return new ArrayList<>();
        }
        int first=0;
        List<String> list=new ArrayList<>();
        for (int i=1;i<nums.length;i++){
            if (nums[i]-nums[i-1]!=1){
                if (first==i-1){
                    list.add(String.valueOf(nums[i-1]));
                }else{
                    list.add(String.valueOf(nums[first]).concat("->").concat(String.valueOf(nums[i-1])));
                }
                first=i;
            }
        }
        if (first==nums.length-1){
            list.add(String.valueOf(nums[nums.length-1]));
        }else{
            list.add(String.valueOf(nums[first]).concat("->").concat(String.valueOf(nums[nums.length-1])));
        }
        return list;
    }

    public static void main(String[] args) {
        System.out.println(new Solution228().summaryRanges(new int[]{0,1,2,4,5,7}));
    }
}
